/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MenuComprarPeixePiscina.java
 *
 * Created on 21/09/2009, 10:27:38
 */

package JPaneis;

import Conector.Conector;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.draw.LineSeparator;
import java.awt.Color;
import java.awt.Component;
import java.awt.Desktop;
import java.awt.GridLayout;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
import siii.MenuPadrao;

public class MenuComprarPeixePiscina extends javax.swing.JPanel {

    private MenuPadrao menuPadrao;
    private Conector conector;
    private static final String numServ = "NUMERO_SERVICO";
    List<Map<String,?>> listaPeixes;
    private float val;
    private float peso;
    private float valorTotal;
    private ImageIcon iconeOK;
    private ImageIcon iconeERRO;
    private ImageIcon iconeATENCAO;
    private boolean peixeEscolhido = false;
    private boolean vendaRealizada = false;


    /** Creates new form MenuComprarPeixePiscina */
    public MenuComprarPeixePiscina(MenuPadrao m, Conector con) {
        this.menuPadrao = m;
        this.conector = con;
        initComponents();
        refreshList();
        iconeOK = new ImageIcon(getClass().getResource("/Images/fish-48x48ok.png"));
        iconeERRO = new ImageIcon(getClass().getResource("/Images/fish-48x48erro.png"));
        iconeATENCAO = new ImageIcon(getClass().getResource("/Images/fish-48x48atencao1.png"));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabelPreco = new javax.swing.JLabel();
        jLabelTotal = new javax.swing.JLabel();
        jButtonConfirmar = new javax.swing.JButton();
        jLabel15 = new javax.swing.JLabel();
        jLabelEspecie = new javax.swing.JLabel();
        jLabelDesconto = new javax.swing.JLabel();
        compraPiscValor = new javax.swing.JLabel();
        jButtonCancelar = new javax.swing.JButton();
        jLabelComprarPeixePiscina = new javax.swing.JLabel();
        compraPiscTotal = new javax.swing.JLabel();
        compraPiscDesconto = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        selList = new javax.swing.JList();
        jLabel3 = new javax.swing.JLabel();
        labelValor = new javax.swing.JLabel();
        compraPiscPeso = new javax.swing.JFormattedTextField();

        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });

        jLabel1.setText("Peso");

        jLabel2.setText("g");

        jLabelPreco.setText("Preço por quilo  R$");

        jLabelTotal.setText("Valor Total");

        jButtonConfirmar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/peixe_add.png"))); // NOI18N
        jButtonConfirmar.setText("Ok");
        jButtonConfirmar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonConfirmarActionPerformed(evt);
            }
        });

        jLabel15.setText("Valor");

        jLabelEspecie.setText("Espécie");

        jLabelDesconto.setText("Desconto");

        compraPiscValor.setText("0.00");

        jButtonCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/peixe_cancelar.png"))); // NOI18N
        jButtonCancelar.setText("Cancelar");
        jButtonCancelar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mouseClickedCancelarHandler(evt);
            }
        });

        jLabelComprarPeixePiscina.setFont(new java.awt.Font("Tahoma", 0, 24));
        jLabelComprarPeixePiscina.setText("Compra de Peixe da Piscina");

        compraPiscTotal.setText("0.00");

        compraPiscDesconto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                compraPiscDescontoKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                compraPiscDescontoKeyReleased(evt);
            }
        });

        selList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                selListValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(selList);

        labelValor.setText("0.00");

        compraPiscPeso.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter()));
        compraPiscPeso.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                compraPiscPesoFocusLost(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(117, 117, 117)
                .addComponent(jLabelEspecie, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE)
                .addGap(670, 670, 670))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(55, 55, 55)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 307, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabelPreco)
                                        .addGap(18, 18, 18)
                                        .addComponent(labelValor, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel1)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(compraPiscPeso, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(25, 25, 25)
                                        .addComponent(jLabel2)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jButtonCancelar)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jButtonConfirmar))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel15)
                                            .addComponent(jLabelDesconto, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabelTotal, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(compraPiscTotal)
                                            .addComponent(compraPiscValor)
                                            .addComponent(compraPiscDesconto, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(119, 119, 119)
                                .addComponent(jLabel3))))
                    .addComponent(jLabelComprarPeixePiscina, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 562, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(171, 171, 171))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addComponent(jLabelComprarPeixePiscina, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addComponent(jLabelEspecie)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel2)
                                    .addComponent(compraPiscPeso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 134, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabelPreco)
                                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(labelValor))
                                .addGap(108, 108, 108))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 259, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(17, 17, 17)))
                        .addGap(41, 41, 41))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel15)
                            .addComponent(compraPiscValor))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelDesconto)
                            .addComponent(compraPiscDesconto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelTotal)
                            .addComponent(compraPiscTotal))
                        .addGap(63, 63, 63)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButtonCancelar)
                            .addComponent(jButtonConfirmar))))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void mouseClickedCancelarHandler(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mouseClickedCancelarHandler
        // TODO add your handling code here:
        menuPadrao.trocaPanel2(menuPadrao.getMenuPrincipal());
    }//GEN-LAST:event_mouseClickedCancelarHandler

    private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
        refreshList();
    }//GEN-LAST:event_formComponentShown

    private void selListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_selListValueChanged
        if(selList.getSelectedIndex() >= 0) {
        peixeEscolhido = true;
        Integer NUMERO_SERVICO = (Integer) listaPeixes.get(selList.getSelectedIndex()).get(numServ);
        val = conector.pegaValorPeixePiscina(NUMERO_SERVICO);
        labelValor.setText(Float.toString(val));
        }
        
    }//GEN-LAST:event_selListValueChanged

    private void compraPiscDescontoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_compraPiscDescontoKeyPressed
        calcula();        // TODO add your handling code here:
    }//GEN-LAST:event_compraPiscDescontoKeyPressed

    private void compraPiscDescontoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_compraPiscDescontoKeyReleased
        calcula();        // TODO add your handling code here:
    }//GEN-LAST:event_compraPiscDescontoKeyReleased

    private void jButtonConfirmarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConfirmarActionPerformed
        
        vendaRealizada = false;
        if(peixeEscolhido) {
        if(peso > 0) {
        if(conector.cadastrarCompraPeixePiscina(valorTotal, peso, listaPeixes.get(selList.getSelectedIndex())))
        {
            JOptionPane.showMessageDialog(this, "Venda realizada com sucesso", "Atenção", JOptionPane.WARNING_MESSAGE, iconeOK);
            vendaRealizada = true;

                    List<Map<String,?>> dadosServico =  conector.doRawSql("SELECT MAX(NUMERO_SERVICO) AS  NUMERO_SERVICO FROM SERVICOS_REALIZADOS_PISCINA");

                    List<Map<String,?>> dadosPesqueiro =  conector.doRawSql("SELECT * FROM PESQUEIROS");

                    String nomePesqueiro = (String) dadosPesqueiro.get(0).get("NOME");
                    String endereco = (String) dadosPesqueiro.get(0).get("LOGRADOURO");
                    String numero = (String) dadosPesqueiro.get(0).get("NUMERO");
                    String bairro = (String) dadosPesqueiro.get(0).get("BAIRRO");
                    String cidade = (String) dadosPesqueiro.get(0).get("CIDADE");
                    String estado = (String) dadosPesqueiro.get(0).get("ESTADO");
                    String cep = (String) dadosPesqueiro.get(0).get("CEP");
                    String tel = (String) dadosPesqueiro.get(0).get("TELEFONE");
                    String email = (String) dadosPesqueiro.get(0).get("EMAIL");
                    System.out.println("DADOS:" + dadosServico.get(0));
                    Integer ordemServico = (Integer) dadosServico.get(0).get("NUMERO_SERVICO");

                        List<Map<String,?>> dadosServico1 =  conector.doRawSql("SELECT * FROM SERVICOS_REALIZADOS_PISCINA WHERE NUMERO_SERVICO = " + ordemServico);

                    String dataHorario = dadosServico1.get(0).get("HORARIO").toString();
                    String especie = dadosServico1.get(0).get("ESPECIE").toString();
                    String servico = dadosServico1.get(0).get("SERVICO").toString();

                    imprimirCupom(  nomePesqueiro, tel, email, endereco, numero, bairro,
                                    cidade, estado, cep, (ordemServico + 1),
                                    dataHorario,
                                    especie,
                                    servico,
                                    peso,
                                    valorTotal);
        }else
            JOptionPane.showMessageDialog(this, "Não foi possível realizar a venda", "Atenção", JOptionPane.WARNING_MESSAGE, iconeERRO);
        }
        else
            JOptionPane.showMessageDialog(this, "Favor informar o peso", "Atenção", JOptionPane.WARNING_MESSAGE, iconeATENCAO);
        }
        else
            JOptionPane.showMessageDialog(this, "Favor escolher o peixe", "Atenção", JOptionPane.WARNING_MESSAGE, iconeATENCAO);

        peixeEscolhido = false;
        this.cleanScreen();
        if(vendaRealizada)
            menuPadrao.trocaPanel2(menuPadrao.getMenuPrincipal());

    }//GEN-LAST:event_jButtonConfirmarActionPerformed

    private void compraPiscPesoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_compraPiscPesoFocusLost
        // TODO add your handling code here:
        calcula();
    }//GEN-LAST:event_compraPiscPesoFocusLost

    public void calcula() {
        peso = Float.parseFloat(compraPiscPeso.getText().length() > 0 ? compraPiscPeso.getText() : "0");
        float desconto = Float.parseFloat(compraPiscDesconto.getText().length() > 0 ? compraPiscDesconto.getText() : "0");
        float valorFinal = (val * peso) / 1000;
        valorTotal = valorFinal - desconto;
        compraPiscValor.setText(Float.toString(valorFinal));
        compraPiscTotal.setText(Float.toString(valorTotal));
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField compraPiscDesconto;
    private javax.swing.JFormattedTextField compraPiscPeso;
    private javax.swing.JLabel compraPiscTotal;
    private javax.swing.JLabel compraPiscValor;
    private javax.swing.JButton jButtonCancelar;
    private javax.swing.JButton jButtonConfirmar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabelComprarPeixePiscina;
    private javax.swing.JLabel jLabelDesconto;
    private javax.swing.JLabel jLabelEspecie;
    private javax.swing.JLabel jLabelPreco;
    private javax.swing.JLabel jLabelTotal;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel labelValor;
    private javax.swing.JList selList;
    // End of variables declaration//GEN-END:variables

     void refreshList() {


        try {
            listaPeixes = (List<Map<String,?>>) conector.doRawSql("SELECT * FROM SERVICOS_DISPONIVEIS_PISCINA");
        } catch (Exception ex) {
            Logger.getLogger(MenuCadastrarEditarServicoPesca.class.getName()).log(Level.SEVERE, null, ex);
            ex.printStackTrace();
        }
          if (listaPeixes == null || listaPeixes.size() == 0)
              return;
          String[][] dados = getListData();
          //set list for JList
          selList.setListData(dados);
          //create Renderer and dislpay
          System.out.println("colunas: " + dados[0].length);
          selList.setCellRenderer((ListCellRenderer) new MyCellRenderer(dados[0].length));
    }

    private String[][] getListData(){
        String[][] dados = null;
//        String campos = "TURNO, PERIODO, TIPO, VALOR";
        //List<Map<String,?>> listaPeixes = null;
        System.out.flush();
        int line = 0;
        int col = 0 ;


        for(Map<String,?> m : listaPeixes){
            if (dados == null){
                dados = new String[listaPeixes.size()][m.size()];
            }
            System.out.println(m);

            for(String key : m.keySet()){
                System.out.println(key + ":" + m.get(key) + ":" + line + ":" + col);
                dados[line][col++] = m.get(key).toString();
            }
            line++;
            col=0;
        }

        return dados;
    }

        static class MyCellRenderer extends JPanel implements ListCellRenderer {

        ArrayList<JLabel> labels = new ArrayList();
        JLabel left, middle, right;
        int cols;

        MyCellRenderer(int cols) {
            this.cols = cols;
            setLayout(new GridLayout(1, cols));
            for (int i=0; i < cols;i++){
                JLabel label = new JLabel();
                label.setOpaque(true);
                add(label);
                labels.add(label);
            }
        }

        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            int i = 0;
            for (JLabel jl : labels) {
                jl.setText(((String[])value)[i++]) ;
                if (isSelected) {
                    jl.setBackground(list.getSelectionBackground());
                    jl.setForeground(list.getSelectionForeground());
                } else {
                    jl.setBackground(list.getBackground());
                    jl.setForeground(list.getForeground());
                }
            }

            setEnabled(list.isEnabled());
            setFont(list.getFont());
            return this;
        }
    }

             public static void abreNoPdf(File path) {
                try {
                    Desktop.getDesktop().open(path);
                } catch (IOException exc) {/*handle exception*/
                    exc.printStackTrace();
                }
            }

            public static void imprimirCupom(
                    String nomePesqueiro, String telefone, String mail, String endereco, String numero, String bairro,
                    String cidade, String estado, String cep,int ordemServico,
                    String dataHorario, String especie, String servico, float peso, float valor){

                    Document document=new Document();
                    try {

                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
                        File pdfFile = new File("comprovante_servico_piscina.pdf");
                        PdfWriter pdfw = PdfWriter.getInstance(document, new FileOutputStream(pdfFile));

                        document.open();

              		PdfPTable table = new PdfPTable(new float[] {50f,10f,30f,30f,10f,40f});
			table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
                        // linha 1
			PdfPCell pesqueiro = new PdfPCell(new Paragraph(nomePesqueiro, new Font(Font.HELVETICA, 30, Font.BOLD)));
                        pesqueiro.setColspan(5);
                        pesqueiro.setBorder(PdfPCell.NO_BORDER);
                        table.addCell(pesqueiro);
                        PdfPCell cel = new PdfPCell(new Paragraph(telefone));
			cel.setColspan(1);
                        cel.setBorder(PdfPCell.NO_BORDER);
                        cel.setVerticalAlignment(PdfPCell.ALIGN_BOTTOM);
                        table.addCell(cel);
                        PdfPCell site = new PdfPCell(new Paragraph("www.pesqueirodomarco.xpg.com.br"));
                        site.setColspan(3);
                        site.setBorder(PdfPCell.NO_BORDER);
                        table.addCell(site);
                        PdfPCell email = new PdfPCell(new Paragraph(mail));
			email.setColspan(3);
                        email.setBorder(PdfPCell.NO_BORDER);
                        table.addCell(email);

                        // linha 2
                        PdfPCell rua = new PdfPCell(new Paragraph(endereco));
                        rua.setBorder(PdfPCell.NO_BORDER);
                        table.addCell(rua);
			table.addCell(numero);
			table.addCell(bairro);
                        table.addCell(cidade);
			table.addCell(estado);
			table.addCell(cep);

			document.add(table);
                        Paragraph pula_linha = new Paragraph(new Phrase(Chunk.NEWLINE));
                        document.add(pula_linha);

                        Paragraph separator = new Paragraph(0);
                        separator.add(new Chunk(new LineSeparator(1, 80, Color.BLACK, Element.ALIGN_CENTER, -2)));

                        document.add(separator);

                        PdfPTable table3 = new PdfPTable(new float[] {90f, 40f, 20f});
                        table3.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
                        table3.addCell("Serviço de Venda da Piscina");
                        table3.addCell("Ordem de Serviço: ");
                        table3.addCell(Integer.toString(ordemServico));


                        document.add(table3);

                        PdfPTable table4 = new PdfPTable(new float[] {80f,30f,50f,20f,40f});
                        table4.addCell("Data e Horário");
                        table4.addCell("Espécie");
                        table4.addCell("Serviço");
                        table4.addCell("Peso");
                        table4.addCell("Valor (R$)");

                        document.add(table4);

                        PdfPTable table5 = new PdfPTable(new float[] {80f,30f,50f,20f,40f});
                        table5.addCell(dataHorario);
                        table5.addCell(especie);
                        table5.addCell(servico);
                        table5.addCell(Float.toString(peso));
                        table5.addCell(Float.toString(valor));

                        document.add(table5);

                        document.add(pula_linha);
                        document.add(separator);

                        Paragraph separator_final = new Paragraph(0);
                        separator_final.add(new Chunk(new LineSeparator(1, 80, Color.LIGHT_GRAY, Element.ALIGN_CENTER, -2)));

                        document.add(separator_final);

                        document.close();
                        pdfw.close();
            try {
                baos.close();
                abreNoPdf(pdfFile);
            } catch (IOException ex) {
                Logger.getLogger(MenuServicoPesca.class.getName()).log(Level.SEVERE, null, ex);
            }

          } catch (DocumentException ex) {
              Logger.getLogger(MenuCadastrarCompraPeixes.class.getName()).log(Level.SEVERE, null, ex);
          }
           catch (FileNotFoundException ex) {
              Logger.getLogger(MenuCadastrarCompraPeixes.class.getName()).log(Level.SEVERE, null, ex);
          }

    }

            public void cleanScreen() {
                compraPiscPeso.setText("");
                compraPiscDesconto.setText("");
                compraPiscValor.setText("0.00");
                compraPiscTotal.setText("0.00");
                valorTotal = 0;
                peso = 0;
                val = 0;
                //selList.setSelectedIndex(-1);
                refreshList();
            }
}
